package com.wswy.wzcx.model.wzdb

import com.wswy.wzcx.ui.wzdb.CertDataEntry
import com.wswy.wzcx.ui.wzdb.WzdbMaps
import timber.log.Timber

class CategoryPhotoCert(val type:Int,
                        val list: List<AddUserCertEntry>) {


    fun getTitle():String =  when (type) {
        CertDataEntry.TYPE_VL -> "行驶证照片"
        CertDataEntry.TYPE_DL -> "驾驶证照片"
        CertDataEntry.TYPE_USER_FACE -> "车主照片"
        CertDataEntry.TYPE_CVA -> "交强险照片"
        else -> "请上传图片"
    }


}

fun classify(list: List<AddUserCertEntry>):List<CategoryPhotoCert>{

    val ret = HashMap<Int,ArrayList<CertDataEntry>>()
    list.forEach {

        val data = WzdbMaps.photoMap.get(it.alias)

        if (data != null){
            //
            var list1 = ret.get(data.type)
            if (list1 == null){
                list1 = ArrayList()
                ret.put(data.type,list1)
            }

            list1.add(data.copy().apply {
                tag = it
            })
        }else{
            //放到未知里面
            var list1 = ret.get(CertDataEntry.TYPE_OTHER)
            if (list1 == null){
                list1 = ArrayList()
                ret.put(CertDataEntry.TYPE_OTHER,list1)
            }
            list1.add(CertDataEntry(it.label?:"",it.alias?:"",399, CertDataEntry.TYPE_OTHER).apply {
                tag = it
            })
        }

    }

    val certs = ArrayList<CategoryPhotoCert>()
    ret.forEach { (t, u) ->
        u.sortBy { it.order }

        certs.add(CategoryPhotoCert(t,u.map { it.tag }.filterNotNull()))

    }

    certs.sortBy { it.type }
    Timber.e("----$certs")

    return certs
}
